<?php
class BaseDateUserModel extends CActiveRecord{
    protected function beforeSave(){
        //auto set date & user   
        if ($this->isNewRecord){// new record 
            $this->createdDate = $this->updatedDate =  new CDbExpression('NOW()');
            $this->createdUserId = $this->updatedUserId = Yii::app()->user->id;
        }
        else{// updating record
            $this->updatedUserId = Yii::app()->user->id; 
            $this->updatedDate =  new CDbExpression('NOW()');
        }
        return parent::beforeSave();
    }
    
    protected function afterSave() {
        Yii::app()->user->setFlash('success', 'Successfully save/alter record - ID: ' . $this->primaryKey);
        
        return parent::afterSave();
    }
    
}
?>
